﻿
/**
* 命名空间: Game.TDBehaviorTree
* 功 能： 节点连接点
* 类 名： ConnectionPoint
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2019/12/12 16:43:05  
*/




using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

namespace Game.TDBehaviorTree
{
    public enum ConnectionPointType
    {
        In,

        Out
    }

    [System.Serializable]
    public class TDConnectionPoint
    {
        public Rect Rect;

        public ConnectionPointType type;

        [System.NonSerialized] public NodeValue Node;

        private int m_FileIndex;

        private GUIStyle style;

        private Action<TDConnectionPoint> OnClickConnectionPoint;

        public TDConnectionPoint(NodeValue node, ConnectionPointType type, GUIStyle style, Action<TDConnectionPoint> OnClickConnectionPoint)
        {
            this.Node = node;
            m_FileIndex = node.m_FileIndex;
            this.type = type;
            this.style = style;
            this.OnClickConnectionPoint = OnClickConnectionPoint;
            Rect = new Rect(0, 0, 10f, 20f);
        }

        public void Draw()
        {
            //根据是否为组合节点还是叶子节点绘制
            Rect.width = 25;
            Rect.height = 15;
            switch (type)
            {
                case ConnectionPointType.In:
                    Rect.x = Node.m_Rect.x + Node.m_Rect.width / 2 - 10;
                    Rect.y = Node.m_Rect.y;
                    break;

                case ConnectionPointType.Out:
                    Rect.x = Node.m_Rect.x + Node.m_Rect.width / 2 - 10;
                    Rect.y = Node.m_Rect.y + Node.m_Rect.height - 10;
                    break;
            }


            if (GUI.Button(new UnityEngine.Rect(Rect.x,Rect.y,Rect.width,Rect.height), "", style))
            {
                if (OnClickConnectionPoint != null)
                {
                    OnClickConnectionPoint(this);
                }
            }


        }


    }


    
}
